<?php
/**
 * Db           系统核心
 * @copyright   Copyright(c) 2024-2034
 * @author      tianjie <527707665@qq.com>
 * @link        http://www.tinphp.com/
 * @version     4.1
 */

namespace tian\Medoo;

use Medoo\Medoo;

/**
 * Model        数据库操作类
 * @copyright   Copyright(c) 2015
 * @author      tianjie
 * @version     2.1
 **/
class MedooDb
{
    protected static $instances = [];

    //构造函数
    public static function instance($name = 'default')
    {
        if (!isset(static::$instances[$name])) {
            $database = config('database');
            $configDb = $database['connections'][$database['default']];
            $options = [
                'type' => $configDb['type'],
                'host' => $configDb['host'],
                'database' => $configDb['database'],
                'username' => $configDb['username'],
                'password' => $configDb['password'],

                'charset' => $configDb['charset'],
                'port' => $configDb['port'],
                'prefix' => $configDb['prefix'],

            ];
            static::$instances[$name] = new Medoo($options);
        }
        return static::$instances[$name];
    }

    public static function __callStatic($name, $arguments)
    {
        return static::instance()->{$name}(... $arguments);
    }

}